package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/2/15 17:02
 * @description
 */
public class Code970 {
    public static void main(String[] args) {
        new Code970().powerfulIntegers(2, 3, 10);
    }

    public List<Integer> powerfulIntegers(int x, int y, int bound) {
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            int num1 = (int)Math.pow(x, i);
            for (int j = 0; j < 20; j++) {
                int num2 = (int)Math.pow(y, j);
                if (num1 + num2 <= bound) {
                    if (!r.contains(num1 + num2)) {
                        r.add(num1 + num2);
                    }
                } else {
                    break;
                }
            }
            if (num1 > bound) {
                break;
            }
        }
        Collections.sort(r);
        return r;
    }
}
